package com.utils.picTxt
{
	import com.utils.picTxt.richTextField.RichTextField;
	
	import fl.controls.UIScrollBar;
	
	import flash.display.Sprite;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	public class OutputTextPanel extends Sprite
	{
		private var _outputText:RichTextField;
		private var _outputTextContainer:Sprite;
		private var _scrollBar:UIScrollBar;
		private var _width:Number=0;
		private var _height:Number=0;
		public function OutputTextPanel(width:Number=415,height:Number=160)
		{
			_width = width;
			_height = height;
			init();
		}
		
		private function init():void
		{
			addContainer();
			addOutputText();
			addScrollBar();
		}
		
		private function addContainer():void
		{
			_outputTextContainer = new Sprite();
			this.addChild(_outputTextContainer);
		}
		
		private function addScrollBar():void
		{
			_scrollBar = getUIScrollBar();
			this.addChild(_scrollBar);
			
			_scrollBar.scrollTarget = _outputText.textfield;
			_scrollBar.x = _outputText.x + _outputText.width;
			_scrollBar.y = _outputText.y;
			_scrollBar.height = _outputText.viewHeight;
			_scrollBar.update();
		}
		
		private function addOutputText():void
		{
			
			_outputText = new RichTextField();
			_outputText.html = true;	//关键
			_outputText.name = "output";
			_outputText.autoScroll = true;
			_outputText.mouseEnabled = false;
			_outputText.textfield.selectable = false;
			_outputText.textfield.mouseWheelEnabled = false;
			_outputText.placeholderMarginH = 1;
			_outputText.textfield.textColor = 16777215;
			_outputText.type = RichTextField.DYNAMIC;
			_outputText.textfield.autoSize =TextFieldAutoSize.LEFT;
			_outputText.defaultTextFormat = new TextFormat("Courier New", 12, 0xFFFFFF, false, false, false);	
			_outputTextContainer.addChild(_outputText);
		}
		
		public function showMsg(msg:XML):void
		{
			_outputText.importXML(msg);
			_outputText.setSize(_width, _outputText.textfield.height);
			_outputTextContainer.graphics.clear();
			_outputTextContainer.graphics.lineStyle(1,0,0);
			_outputTextContainer.graphics.moveTo(0,0);
			_outputTextContainer.graphics.lineTo(0,_outputText.height);
			_outputTextContainer.graphics.endFill();
			_scrollBar.update();
		}
		
		private function getUIScrollBar():UIScrollBar
		{
			var scrollBar:UIScrollBar = new UIScrollBar();
			scrollBar.setStyle("trackUpSkin", ScrollBars_trackSkin);
			scrollBar.setStyle("trackOverSkin", ScrollBars_trackSkin);
			scrollBar.setStyle("trackDownSkin", ScrollBars_trackSkin);
			scrollBar.setStyle("trackDisabledSkin", ScrollBars_trackSkin);			
			scrollBar.setStyle("thumbUpSkin", ScrollBars_thumbUpSkin);
			scrollBar.setStyle("thumbOverSkin", ScrollBars_thumbOverSkin);
			scrollBar.setStyle("thumbDownSkin", ScrollBars_thumbDownSkin);
			scrollBar.setStyle("thumbIcon", ScrollBars_thumbIcon);			
			scrollBar.setStyle("downArrowUpSkin", ScrollBars_downArrowUpSkin);
			scrollBar.setStyle("downArrowOverSkin", ScrollBars_downArrowOverSkin);
			scrollBar.setStyle("downArrowDownSkin", ScrollBars_downArrowDownSkin);
			scrollBar.setStyle("downArrowDisabledSkin", ScrollBars_downArrowDisabledSkin);
			scrollBar.setStyle("upArrowUpSkin", ScrollBars_upArrowUpSkin);
			scrollBar.setStyle("upArrowOverSkin", ScrollBars_upArrowOverSkin);
			scrollBar.setStyle("upArrowDownSkin", ScrollBars_upArrowDownSkin);
			scrollBar.setStyle("upArrowDisabledSkin", ScrollBars_upArrowDisabledSkin);
			return scrollBar;
		}
		
		
		
		
		
		
		
		
		
		
	}
}